var app = getApp();

Page({
  data: {
    expressId: null,
    express: {}
  },
  onLoad(query) {
    console.log(query)
    this.setData({
      expressId: query.expressId
    })
  },
  onShow() {
    this.getExpress()
  },
  acceptExpress() {
    let userId = app.globalData.userInfo.userId
    if(this.data.express.publishId === userId){
      dd.showToast({
        type: 'fail',
        content: '自己发布的订单不能接收',
        duration: 3000,
        success: () => {
          
        },
      })
    } else {
      dd.httpRequest({
        url: app.globalData.url + '/express/update',
        method: 'POST',
        data: {
          expressId: this.data.expressId,
          acceptId: userId,
          orderStatus: '1002' // 已接受
        },
        dataType: 'json',
        success: (res) => {
          dd.showToast({
            type: 'success',
            content: '接收成功',
            duration: 2000,
            success: () => {
              dd.switchTab({
                url: '/pages/order/order'
              })
            }
          })
        },
        fail: (res) => {
          console.log("httpRequestFail---", res)
          dd.alert({ content: JSON.stringify(res) });
        },
        complete: (res) => {
          
        }
      });
    }
  },
  getExpress() {
    dd.httpRequest({
      url: app.globalData.url + '/express/get',
      data: {
        expressId: this.data.expressId
      },
      dataType: 'json',
      success: (res) => {
        this.setData({
          express: res.data.data
        })
      },
      fail: (res) => {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: (res) => {
        dd.hideLoading();
      }
    });
  }
});
